<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>我要投稿</title>
		<%@ include file="../../../common/Admin-list.jsp"%>		
		<script type="text/javascript" src="<%=bpath %>Scripts/jquery/jquery.colorpicker.js"></script> 	
		
		<!-- 配置文件 -->
	    <script type="text/javascript" src="<%=path %>/Scripts/UEditor/ueditor.config.js"></script>
	    <!-- 编辑器源码文件 -->
	    <script type="text/javascript" src="<%=path %>/Scripts/UEditor/ueditor.all.js"></script>		
		  
		<script type="text/javascript" src="<%=bpath %>Scripts/jquery/jquery.form.js"></script> 		 
		 
		<script type="text/javascript">	
		var subUrl="../ArticleList/save.json";
		$(function(){
			
			// 所属类目			
			$('#categoryID').combotree({
				 url: '../ArticleCategory/getEasyUiTreeForSelect.json?isContribute=1',  //开放投稿
				 valueField: 'id',
	             textField: 'text',
	             editable: false ,//可编辑--定义用户是否可以直接输入
	             onClick: function (node) { 
		            	$("#categoryName").val($("#categoryID").combotree("getText"));	            	
		         }, //全部折叠      
	             onLoadSuccess: function (node, data) {        
	              // $('#parentID').combotree('tree').tree("collapseAll"); 
	             }
			});
			
			if('${data.type}'!=null&&'${data.type}'=="add"){ //新增模块
				$("#lblTitle").html('新增稿件');
				$('#menuSort,#trRemark').css('display','none');
			}else if('${data.type}'!=null&&'${data.type}'=="edit"){ //编辑模块				
				$("#lblTitle").html('编辑投稿');
				$('#menuSort,#trRemark').css('display','none');	
				if('${data.articleList.issue}'=="0"){
					$("#issue").attr("checked",false);
				}				
				if('${data.articleList.isHomePic}'=="1"){
					$("#isHomePic").attr("checked",true);
				}				
				if('${data.articleList.isRecommend}'=="1"){
					$("#isRecommend").attr("checked",true);
				}				
				$("#articleSite").val('${data.articleList.articleSite}');				
				$("#id").val('${data.articleList.id}');			
				$("#title").val('${data.articleList.title}');	
				$("#subTitle").val('${data.articleList.subTitle}');	
				$("#title").css("color",'${data.articleList.titleColor}');
			    $("#titleColor").val('${data.articleList.titleColor}');			    	
				$("#categoryID").combotree("setValue",'${data.articleList.categoryID}');				
				$("#categoryName").val('${data.articleList.categoryName}');	
				$("#sortID").val('${data.articleList.sortID}');				
				$("#status").val('${data.articleList.status}');	
				if('${data.articleList.status}'=="3"){ 
					$('#trRemark').css('display','table-row');
				}				
				subUrl="../ArticleList/update.json";
			}
			
			/*
				//标题颜色选择
				$("#cp4").colorpicker({
				    fillcolor:true,
				   // event:'mouseover',
				    success:function(o,color){
				        $("#title").css("color",color);
				        $("#titleColor").val(color);
				    }
				});
				$("#colorpanel").css("z-index",999);
		
			*/
			
				
			//重构artDialog.prompt方法，让它支持多行文本
			artDialog.prompt = function (content, yes, value) {
	            value = value || '';
	            var input;
	            return artDialog({
	                id: 'Prompt',
	                icon: 'question',
	                fixed: true,
	                lock: true,
	                opacity: .1,	               
	                content: [
	            '<div style="margin-bottom:5px;font-size:12px">',
	                content,
	            '</div>',
	            '<div>',
	                '<textarea cols="100" rows="50" >' + value + '</textarea>',
	            '</div>'
	            ].join(''),
	                init: function () {
	                    input = this.DOM.content.find('textarea')[0];
	                    input.select();
	                    input.focus();
	                },
	                ok: function (here) {
	                    return yes && yes.call(this, input.value, here);
	                },
	                cancel: true
	            });
	        };
			
			
		});
		
		function lnbSave(st){
				//保存 status;//状态 草稿0,待审1,审核通过2,审核失败3
				$("#status").val(st);	
				if(st=="3"){ //失败理由					
					art.dialog.prompt("请输入驳回理由！", function (data) {							
							$('#remark').val(data);							
							$("#issue").attr("checked",false);		
							
							$("#addForm").ajaxSubmit({
								url:subUrl,
								type:"POST",
								async:false,
								beforeSubmit:checkForm,
								contentType:"application/x-www-form-urlencoded;charset=UTF-8",
								error:function(){},
								success:function(data){
									if(data.success==true){
										showTip("保存成功，返回列表页面！","succeed");					    	
									}else{										 
										art.dialog.alert('保存失败，请确认填写正确！');
									}
								}
							});
							
						}, $('#remark').val());
				}else {
					if(st=="2"){
						$("#issue").attr("checked",true);
					}
					$("#addForm").ajaxSubmit({
						url:subUrl,
						type:"POST",
						async:false,
						beforeSubmit:checkForm,
						contentType:"application/x-www-form-urlencoded;charset=UTF-8",
						error:function(){},
						success:function(data){
							if(data.success==true){
								showTip("保存成功，返回列表页面！","succeed");					    	
							}else{
								//showTip("操作失败","warning");  
								art.dialog.alert('保存失败，请确认填写正确！');
							}
						}
					});
				}				
				
		}
			
		function checkForm(){
			var flag=$('#addForm').form('validate');
			return flag;
		}
				
		//消息提示  
		function showTip(mess,icon) {  
		    art.dialog({  
		        id : 'Tip',  
		        title : '消息',  
		        fixed : true,  
		        lock : true,  
		        opacity: .2,  
		        content : mess,  
		        icon : icon,  
		        time : 1  
		    });  
		    setTimeout('originReload()', 1000);  
		}  
		
		//重载来源页面  
		function originReload(){  
		    var win = art.dialog.open.origin;		    
		    win.location.reload();  
		}		
	
		
		
	
		
			
		</script>
		<style>
			input{
				line-height:22px;					
			}
		</style>
		
</head>
<body>
<!---->
<div>
	<div id="tab">
        <ul>
            <li class="Current">
            	<a href="#" onfocus="this.blur()">
            		<span id="lblTitle" >  新增投稿  </span>
            	</a>
            </li>
        </ul>
    </div>  
    <div id="menu">
        <ul>
          <%if(null==request.getParameter("isAudit")){%> 
            <li>
            	<a href="javascript:lnbSave(0)" >
            		<span><img src="<%=basePath %>pages/Admin/Images/Icon/save.gif" alt="Save" />保存草稿</span>
            	</a>
            </li>
            <li>
            	<a  href="javascript:lnbSave(1)" >
            		<span><img src="<%=basePath %>pages/Admin/Images/Icon/ok.gif" alt="Save" />保存并提交</span>
            	</a>
            </li>      
            <% } else {%>
            <li>
            	<a  href="javascript:lnbSave(2)" >
            		<span><img src="<%=basePath %>pages/Admin/Images/Icon/accept.gif" alt="accept" />审核通过</span>
            	</a>
            </li>
            <li>
            	<a  href="javascript:lnbSave(3)" >
            		<span><img src="<%=basePath %>pages/Admin/Images/Icon/cancel.gif" alt="cancel" />驳回</span>
            	</a>
            </li>   
            <%} %>      
            <li style="color:red;margin-left:40%;font-size:16px;">上网信息不涉密，涉密信息不上网</li>
        </ul>
    </div>   
    
    <div id="middle"> 
    <form action="../ArticleList/save.json" id="addForm" name="addForm" method="post" >   
    <div class="editor">
        <table class="eTable">
        	
        	<tr class="eTr">
                <td class="name">
                    <label id="Label4">投稿栏目</label>
                </td>
                <td>
                	<select id="categoryID" name="categoryID"  required="true" class="easyui-validatebox validatebox-text easyui-combotree" style="width:200px;line-height:20px;"></select>
                	<input id="categoryName" name="categoryName" type="hidden" ></input>   
                </td>
            </tr>
        	<%if("yes".equals(request.getParameter("isAudit"))){%> <!-- 是否审核  -->   
            <tr class="eTr">
                <td class="name">         
                	 <label id="Label21" >网站显示</label>           
                </td>
                <td>	
                	 <input id="issue" type="checkbox" name="issue" checked="checked" value="1"  style="vertical-align:middle;"/>
                	 <label for="issue">网站显示</label>
                	 &nbsp;&nbsp;&nbsp;&nbsp;
                	 <input id="isHomePic" type="checkbox" name="isHomePic"  value="1" style="vertical-align:middle;"/>
                	 <label for="isHomePic">首页图片新闻</label>
                	 &nbsp;&nbsp;&nbsp;&nbsp;
                	 <input id="isRecommend" type="checkbox" name="isRecommend" value="1" style="vertical-align:middle;"/>
                	 <label for="issue">列表置顶</label>                	 
				</td>
            </tr>
            <%} %>
          <tr class="eTr">
                <td class="name">
                   <label>文章目标平台：</label>	
                </td>
                <td>
                    <select id="articleSite" class="datatype"  name="articleSite">
						<option value="0" selected="selected">&nbsp;&nbsp;外网发布</option>							
						<option  value="1">&nbsp;&nbsp;内网发布&nbsp;&nbsp;</option>	
						<option  value="2">&nbsp;&nbsp;内网&外网发布</option>	
					</select>
                </td>
            </tr> 
            <tr class="eTr">
                <td class="name">
                    <label id="LabelName" >文章标题</label>
                </td>
                <td>
                    <!--<img src="<%=basePath %>Themes/default/images/colorpicker.png" id="cp4" style="cursor:pointer"/>  -->
                    <input id="title" name="title" required="true" class="easyui-validatebox validatebox-text input" ></input>
                    <input id="titleColor" name="titleColor" type="hidden"></input>
                     
                    <input id="id" name="id" type="hidden"></input>
                   	<input id="status" name="status" type="hidden"  value="0"></input>     
                    <input id="is_contribute" name="is_contribute"  type="hidden" value="1"></input>                   
                </td>
            </tr>        
            <tr class="eTr">
                <td class="name">
                    <label id="LabelName" >副标题</label>                    
                </td>
                <td>
                     <input id="subTitle" name="subTitle" class="easyui-validatebox validatebox-text input"></input>
                </td>
            </tr>
            <tr class="eTr" id="menuSort">
                <td class="name">
                    <label id="Label5" >文章排序</label></td>
                <td>
                    <input id="sortID" name="sortID" class="input" value="0"></input>
                </td>
            </tr>
            
            <tr class="eTr" id="trRemark">
                <td class="name" valign="top">
                    <label id="Label5" style="color:red;" >驳回理由：</label>
                </td>
                <td>
                    <textarea cols=40 rows=5  id="remark" name="remark">${data.articleList.remark}</textarea>
                </td>
            </tr>                    
            <!-- 百度编辑器  -->            
            <tr class="eTr">                
                <td colspan="2" >
                	<!-- 加载编辑器的容器 -->
				    <script id="container" name="contents" type="text/plain" style="width:100%;height:240px;">
        				
    				</script>
                </td>
            </tr>
            
            
        </table>
        
    </div>
    </form> 
    </div>
    
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('container',{
        	autoClearinitialContent:true, //清除初始内容      
        	autoHeightEnabled: false,//是否自动长高，默认true
        	autoFloatEnabled:false, //是否保持toolbar的位置不动，默认true        	
        	topOffset :70        	//浮动时工具栏距离浏览器顶部的高度，用于某些具有固定头部的页面
        });        
              
       ue.ready(function() {
		    ue.setContent('${data.articleList.contents}');
		});		
    </script>
    
</div>
</body>
</html>